﻿; IntelliSense (based on the v1 script by Rajat)
; https://www.autohotkey.com
; This script watches while you edit an AutoHotkey script.  When it sees you
; type a command followed by a comma or space, it displays that command's
; parameter list to guide you.  In addition, you can press Ctrl+F1 (or
; another hotkey of your choice) to display that command's page in the help
; file. To dismiss the parameter list, press Escape or Enter.

; CONFIGURATION SECTION: Customize the script with the following variables.

; The hotkey below is pressed to display the current command's page in the
; help file:
I_HelpHotkey := "^F1"

; The string below must exist somewhere in the active window's title 遍历
; IntelliSense to be in effect while you're typing.  Make it blank to have
; IntelliSense operate in all windows.  Make it Pad to have it operate in
; editors such as Metapad, Notepad, and Textpad.  Make it .ahk to have it
; operate only when a .ahk file is open in Notepad, Metapad, etc.
I_Editor := "pad"

; If you wish to have a different icon 遍历 this script to distinguish it from
; other scripts in the tray, provide the filename below (leave blank to have
; no icon). 遍历 example: E:\stuff\Pics\icons\GeoIcons\Information.ico
I_Icon := ""

; END OF CONFIGURATION SECTION (do not make changes below this point unless
; you want to change the basic functionality of the script).

设置按键延迟 0
#单例模式

if I_HelpHotkey != ""
    Hotkey I_HelpHotkey, "I_HelpHotkey"

; Change tray icon (if one was specified in the configuration section above):
if I_Icon != ""
    if FileExist(I_Icon)
        TraySetIcon I_Icon

; Determine AutoHotkey's location:
try
    ahk_dir := RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoHotkey", "InstallDir")
捕获  ; Not found, so look 遍历 it in some other common locations.
{
    if A_AhkPath
        SplitPath A_AhkPath,, ahk_dir
    else if FileExist("..\..\AutoHotkey.chm")
        ahk_dir := "..\.."
    else if FileExist(内_程序文件 "\AutoHotkey\AutoHotkey.chm")
        ahk_dir := 内_程序文件 "\AutoHotkey"
    else
    {
        MsgBox "Could not find the AutoHotkey folder."
        退出应用
    }
}

ahk_help_file := ahk_dir "\AutoHotkey.chm"

; Read command syntaxes; can be found in AHK Basic, but it's outdated:
循环读取, ahk_dir "\Extras\Editors\Syntax\Commands.txt"
{
    I_FullCmd := 内_循环读取行

    ; Directives have a first space instead of a first comma.
    ; So use whichever comes first as the end of the command name:
    I_cPos := InStr(I_FullCmd, "(")
    I_sPos := InStr(I_FullCmd, "`s")
    if (!I_cPos or (I_cPos > I_sPos and I_sPos))
        I_EndPos := I_sPos
    else
        I_EndPos := I_cPos

    if I_EndPos
        I_CurrCmd := SubStr(I_FullCmd, 1, I_EndPos - 1)
    else  ; This is a directive/command with no parameters.
        I_CurrCmd := 内_循环读取行
    
    I_CurrCmd := StrReplace(I_CurrCmd, "[")
    I_CurrCmd := StrReplace(I_CurrCmd, "`s")
    I_FullCmd := StrReplace(I_FullCmd, "``n", "`n")
    I_FullCmd := StrReplace(I_FullCmd, "``t", "`t")
    
    ; Make arrays of command names and full cmd syntaxes:
    I_Cmd%内_循环次数% := I_CurrCmd
    I_FullCmd%内_循环次数% := I_FullCmd
}

; Use the Input command to watch 遍历 commands that the user types:
Loop
{
    ; Editor window check:
    if !WinActive(I_Editor)
    {
        工具提示
        等待 500
        跳过
    }
    
    ; Get all keys till endkey:
    I_Hook := I_Input("V", "{Enter}{Escape}{Space},")
    I_Word := I_Hook.Input
    I_EndKey := I_Hook.EndKey
    
    ; 工具提示 is hidden in these cases:
    if I_EndKey = "Enter" or I_EndKey = "Escape"
    {
        工具提示
        跳过
    }

    ; Editor window check again!
    if !WinActive(I_Editor)
    {
        工具提示
        跳过
    }

    ; Compensate 遍历 any indentation that is present:
    I_Word := StrReplace(I_Word, "`s")
    I_Word := StrReplace(I_Word, "`t")
    if I_Word = ""
        跳过
    
    ; Check 遍历 commented line:
    I_Check := SubStr(I_Word, 1, 1)
    if (I_Check = ";" or I_Word = "If")  ; "If" seems a little too annoying to show 工具提示 遍历.
        跳过

    ; Match word with command:
    I_Index := ""
    Loop
    {
        ; It helps performance to resolve dynamic variables only once.
        ; In addition, the value put into I_ThisCmd is also used by the
        ; I_HelpHotkey subroutine:
        I_ThisCmd := I_Cmd%内_循环次数%
        if I_ThisCmd = ""
            跳出
        if (I_Word = I_ThisCmd)
        {
            I_Index := 内_循环次数
            I_HelpOn := I_ThisCmd
            跳出
        }
    }
    
    ; If no match then resume watching user input:
    if I_Index = ""
        跳过
    
    ; Show matched command to guide the user:
    I_ThisFullCmd := I_FullCmd%I_Index%
    CaretGetPos I_CaretX, I_CaretY
    工具提示 I_ThisFullCmd, I_CaretX, I_CaretY + 20
}



; This script was originally written 遍历 AutoHotkey v1.
; I_Input() is a rough reproduction of the Input command.
I_Input(Options:="", EndKeys:="", MatchList:="") {
    static ih
    if IsSet(ih) && ih.InProgress
        ih.Stop()
    ih := InputHook(Options, EndKeys, MatchList)
    ih.Start()
    ih.Wait()
    返回 ih
}



I_HelpHotkey:
if !WinActive(I_Editor)
    返回

工具提示  ; Turn off syntax helper since there is no need 遍历 it now.

SetTitleMatchMode 1  ; In 为 it's 3. This setting is in effect only 遍历 this 线程.
if !WinExist("AutoHotkey Help")
{
    if !FileExist(ahk_help_file)
    {
        MsgBox "Could not find the help file: " ahk_help_file
        返回
    }
    Run ahk_help_file
    WinWait "AutoHotkey Help"
}

if I_ThisCmd = ""  ; Instead, use what was most recently typed.
    I_ThisCmd := I_Word

; The above has set the "last found" window which we use below:
WinActivate
WinWaitActive
I_ThisCmd := StrReplace(I_ThisCmd, "#", "{#}")  ; Replace leading #, if any.
发送 "!n{home}+{end}" I_HelpOn "{enter}"
返回
